package com.leo.entity;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.dsl.components.KeepOnScreenComponent;
import com.almasb.fxgl.dsl.views.ScrollingBackgroundView;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.EntityFactory;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.Spawns;
import javafx.geometry.Orientation;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-19  22:43
 * @Description: TODO
 */
public class ScrollEntityFactory implements EntityFactory {

    @Spawns("bg")
    public Entity createBg(SpawnData spawnData) {
        ScrollingBackgroundView backgroundView =
                new ScrollingBackgroundView(FXGL.image("hor.jpg"), FXGL.getAppWidth(), FXGL.getAppHeight(), Orientation.HORIZONTAL);

        return FXGL.entityBuilder(spawnData)
                .view(backgroundView)
                .build();
    }

    @Spawns("player")
    public Entity createPlayer(SpawnData spawnData) {
        return FXGL.entityBuilder(spawnData)
                .view(new Rectangle(50, 50, Color.RED))
                .with(new KeepOnScreenComponent())
                .build();
    }
}
